Repository navigation
py_loader: implement metacall_await in the python port - #955
Open
bhuvan-somisetty wants to merge 3 commits into
Open
bhuvan-somisetty wants to merge 3 commits into
bhuvan-somisetty wants to merge 3 commits into
Conversation
Enable the test for metacall_await in the Python port and fix two bugs in its script: threading was not imported, and result was assigned as a local inside test() instead of the global. It fails for now because the Python port does not implement metacall_await yet.
metacall_await from the python port will return a concurrent future, so the caller blocks on result() while the background loop runs the coroutine. Drop asyncio.run, the lock and the global, and add a timeout so the test can not hang if the future never resolves.
metacall_await returns a concurrent.futures.Future. The caller can block on result() while the loader runs the async function and settles the future from its own thread, through the resolve and reject callbacks of metacall_await_s. concurrent.futures.Future is thread safe, so the callbacks call set_result and set_exception directly. A rejected value that is not an exception is wrapped into a RuntimeError.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
metacall_awaitin the python port, the stub that was under#if 0inpy_loader_port.c. Scope agreed with viferga on Discord (2026-11-11).Approach
metacall_await(name, *args)returns aconcurrent.futures.Future. The caller can block onf.result()while the loader runs the async function and settles the future from its own thread, through the resolve and reject callbacks ofmetacall_await_s.concurrent.futures.Futureis thread safe, so the callbacks take the GIL and callset_result/set_exceptiondirectly, no loop helpers neededRuntimeErrormetacall_await_sreturns NULL, aRuntimeErroris raised; the returned value is destroyed right awaymetacall_awaitis exported fromapi.pyand__init__.pyCommits
tests: enable metacall_python_await_testtests: use the sync form in metacall_python_await_test:f = metacall_await('yeet', 1234); f.result(timeout=10)py_loader: implement metacall_await in the python portTests
Local Windows MSVC Debug build (Python 3.10):
metacall-python-await-testandmetacall-python-async-testpass, no build warnings. clang-format 21 check passes.Open points
await metacall_await(...)inside a coroutine needsasyncio.wrap_future, planned as a follow upAI-Assisted
Claude Code